package com.fsxgt.datagrid.component.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fsxgt.datagrid.component.bo.CmpHttpRequestBO;
import com.fsxgt.datagrid.component.dao.CmpHttpRequestMapper;
import com.fsxgt.datagrid.flow.dao.FlowInfoMapper;
import com.fsxgt.datagrid.flow.service.IComponentService;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @ClassName: CmpHttpRequestService
 * @Description: TODO(描述)
 * @author liuyi
 * @date 2024-02-29 12:53:27
 */
@Slf4j
@Service
public class CmpHttpRequestService implements IComponentService{
	
	@Autowired
	private FlowInfoMapper flowInfoMapper;
	
	@Autowired
	private CmpHttpRequestMapper cmpHttpRequestMapper;

	
	@Transactional(rollbackFor = Exception.class)
	public void saveCmpHttpRequest(CmpHttpRequestBO CmpHttpRequestBO) {
		CmpHttpRequestBO bo = cmpHttpRequestMapper.get(CmpHttpRequestBO.getFlowInfoId(),CmpHttpRequestBO.getComponentSeq());
		if(bo==null) {
			cmpHttpRequestMapper.insert(CmpHttpRequestBO);
		}else {
			cmpHttpRequestMapper.update(CmpHttpRequestBO);
		}
		
	
		
		flowInfoMapper.updateFlowComponentName(CmpHttpRequestBO.getName(), CmpHttpRequestBO.getFlowInfoId(), CmpHttpRequestBO.getComponentSeq());

		
	}
	@Transactional(rollbackFor = Exception.class)
	public void deleteComponent(CmpHttpRequestBO CmpHttpRequestBO) {
		deleteComponent(CmpHttpRequestBO.getFlowInfoId(),CmpHttpRequestBO.getComponentSeq());
	}
	/**  
	 * @Title: deleteComponent
	 * @Description: TODO(描述)
	 * @param flowInfoId
	 * @param seq 
	 * @see com.fsxgt.datagrid.core.service.impl.IComponentService#deleteComponent(java.lang.String, java.lang.String) 
	 * @author liuyi
	 * @date 2023-05-08 09:08:12 
	 */ 
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteComponent(String flowInfoId, String seq) {
		// TODO Auto-generated method stub
		cmpHttpRequestMapper.delete(flowInfoId,seq);

	}
	/**  
	 * @Title: getComponentType
	 * @Description: TODO(描述)
	 * @return 
	 * @see com.fsxgt.datagrid.core.service.impl.IComponentService#getComponentType() 
	 * @author liuyi
	 * @date 2023-05-08 09:08:12 
	 */ 
	@Override
	public String getComponentType() {
		// TODO Auto-generated method stub
		return "Http Request";
	}
	/**  
	 * @Title: getSyncOffline
	 * @Description: TODO(描述)
	 * @param bo
	 * @author liuyi
	 * @date 2023-05-08 09:51:14 
	 */  
	public CmpHttpRequestBO getCmpHttpRequest(CmpHttpRequestBO CmpHttpRequestBO) {
		// TODO Auto-generated method stub
		CmpHttpRequestBO bo = cmpHttpRequestMapper.get(CmpHttpRequestBO.getFlowInfoId(),CmpHttpRequestBO.getComponentSeq());

		
		return bo;
	}
	/**  
	 * @Title: getConfig
	 * @Description: TODO(描述)
	 * @param flowId
	 * @param seq
	 * @return 
	 * @see com.fsxgt.datagrid.core.service.IComponentService#getConfig(java.lang.String, java.lang.String) 
	 * @author liuyi
	 * @date 2023-05-25 15:24:47 
	 */ 
	@Override
	public Object getConfig(String flowId, String seq) {
		// TODO Auto-generated method stub
		
		CmpHttpRequestBO bo = new CmpHttpRequestBO();
		bo.setFlowInfoId(flowId);
		bo.setComponentSeq(seq);
		
		return getCmpHttpRequest(bo);
	}
}
